package net.jescort.persistence.dao.eclipselink;

import java.util.List;
import javax.persistence.Query;
import net.gelif.kernel.persistence.dao.eclipselink.GenericEclipseLinkDao;
import net.jescort.domain.user.Email;
import net.jescort.domain.user.EmailPk;
import net.jescort.persistence.dao.EmailDao;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;


@Repository("emailDao")
@Scope(BeanDefinition.SCOPE_SINGLETON)
public class EmailJpaDao extends GenericEclipseLinkDao<Email, EmailPk> implements EmailDao
{
    @SuppressWarnings("unchecked")
    public List<Email> getListByUserId(int userId)
    {
        return entityManager.createNativeQuery("SELECT * FROM emails WHERE user_id = ?").setParameter(1, userId).getResultList();
    }
    
    @SuppressWarnings("unchecked")
    public List<Email> getListByUserId(int userId, int offset, int limit)
    {
        Query query = entityManager.createNativeQuery("SELECT * FROM emails WHERE user_id = ?").setParameter(1, userId);
        query.setFirstResult(offset);
        query.setMaxResults(limit);
        return query.getResultList();
    }
}
